package cheme.ProcessModel.Cmds;

import cheme.ProcessModel.ContentsModel;
import cheme.ProcessModel.ProcessModel;
import cheme.ProcessModel.SimpleLogger;
import org.eclipse.gef.commands.Command;

public class ContentModelCommand extends Command
{
private static String me = "cheme.ProcessModel.Cmds.ContentModelCommand";
	
	private ContentsModel contentsModel;

	private ProcessModel pmModel;

	/*
	 * It appears that this command does not actual create the model element,
	 * but only introduces a previsouly created element to the model. As such
	 * the implementation is very easy... contentsModel.addChild(...)
	 * 
	 * (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#execute()
	 */
	public void execute()
	{
		SimpleLogger.log(me, me + ".execute()");
		
		contentsModel.addChild(pmModel);
	}

	/*
	 * Note here that the commands are indeed more part of the model than 
	 * anything else. With intamate knowldge of the model as in 
	 * setContentsModel, it is tightly coupled with that model.
	 */
	public void setContentsModel(Object model)
	{
		SimpleLogger.log(me, me + ".setContentsModel(model)");
		
		contentsModel = (ContentsModel) model;
	}

	/*
	 * Note here that the commands are indeed more part of the model than 
	 * anything else. With intamate knowldge of the model as in setHelloModel,
	 * it is tightly coupled with that model.
	 */
	public void setHelloModel(Object model)
	{
		SimpleLogger.log(me, me + ".setHelloModel(model)");
		
		pmModel = (ProcessModel) model;
	}

	/*
	 * Just as the execute method is trival... so is the undo! Yay!
	 * 
	 * (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#undo()
	 */
	public void undo()
	{
		SimpleLogger.log(me, me + ".undo()");
		
		contentsModel.removeChild(pmModel);
	}

}
